package com.micro.modual.service.impl;

import com.micro.common.MicroResponseCode;
import com.micro.common.util.JacksonUtil;
import com.micro.core.exception.BizException;
import com.micro.core.frame.service.impl.AbstractBasicsServiceImpl;
import com.micro.core.resp.RespJson;
import com.micro.core.resp.RespJsonData;
import com.micro.modual.entity.GoodsBrand;
import com.micro.modual.extension.GoodsBrandExtension;
import com.micro.modual.mapper.GoodsBrandMapper;
import com.micro.modual.model.bo.goodsbrand.GoodsBrandBO;
import com.micro.modual.model.dto.goodsbrand.GoodsBrandDetailDTO;
import com.micro.modual.service.GoodsBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


/**
*  <h1>商品品牌表  实现</h1>
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:11:10
 */
@Service("goodsBrandService")
public class GoodsBrandServiceImpl extends AbstractBasicsServiceImpl<GoodsBrand,Long> implements GoodsBrandService {

    @Autowired
    private GoodsBrandMapper goodsBrandMapper;

    /**
     * <h2>新增商品品牌表详情</h2>
     * @param goodsBrandBO {@link GoodsBrandBO} 商品品牌表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson addGoodsBrand(GoodsBrandBO goodsBrandBO) {
        GoodsBrand goodsBrand = GoodsBrandExtension.converAddGoodsBrand(goodsBrandBO);
        goodsBrandMapper.insertSelective(goodsBrand);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(), MicroResponseCode.SUCCESS.getResponseMessage());
    }

    /**
     * <h2>修改商品品牌表详情</h2>
     * @param goodsBrandBO  {@link GoodsBrandBO} 商品品牌表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson editGoodsBrand(GoodsBrandBO goodsBrandBO) {
        GoodsBrand goodsBrand = GoodsBrandExtension.converEditGoodsBrand(goodsBrandBO);
        goodsBrandMapper.updateByPrimaryKeySelective(goodsBrand);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());

    }

    /**
     * <h2>根据主键编号删除商品品牌表信息</h2>
     * @param id  商品品牌表 主键编号
     * @return  {@link RespJson} 返回结果基础类
     */

    @Override
    public RespJson deleteGoodsBrand(Long id) {
        goodsBrandMapper.deleteByPrimaryKey(id);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());
    }

    @Override
    public RespJsonData<List<GoodsBrandDetailDTO>> findBrandList() {
        List<GoodsBrand> goodsBrandList = goodsBrandMapper.findBrandList();
        List<GoodsBrandDetailDTO> goodsBrandDetailDTOList = JacksonUtil.getList(JacksonUtil.toJson(goodsBrandList),GoodsBrandDetailDTO.class);
        return new RespJsonData<List<GoodsBrandDetailDTO>>(goodsBrandDetailDTOList,MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());

    }

}
